{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名  宁越\n",
    "+ 学号  0164964"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "入道云指さした君に会いたいなぁ\n",
      "揺れる揺れる　心と心がまた揺らいでいる\n",
      "受け入れたつもりでいたのにいつの间にか　记忆も存在も手が届かないとこに隠すようにして/nはぐらかしてた/n\n",
      "九月の终わりの晴れ间は夏がまだ残っていて\n",
      "照りつける日差しと共に追忆を连れてくる\n",
      "夕立が过ぎ去った空　「ソフトクリームのようだね」と\n",
      "\n",
      "はぐらかしてた/n时が解决してくれるとよく耳にするけれど/nでも　解决が“忘れること”なら仆はそれを望んじゃいない/n思い出は时に暧昧で　美しくすり替わっていく/nそれでもいい　そうだとしても忘れたくない\n",
      "九月の终わりの晴れ间は夏がまだ残っていて\n",
      "照りつける日差しと共に追忆を连れてくる\n",
      "夕立が过ぎ去った空　「ソフトクリームのようだね」と\n",
      "\n",
      "九月の终わりの晴れ间は夏がまだ残っていて\n",
      "照りつける日差しと共に追忆を连れてくる\n",
      "夕立が过ぎ去った空　「ソフトクリームのようだね」と\n",
      "\n",
      "君に会いたいなぁ/n风に乗って　香る金木犀が仆に伝えている/nもう夏は终わってるんだよ、と/nいつの日にかこの季节を越えて歩き出せたなら　また记忆の中で/n\n"
     ]
    }
   ],
   "source": [
    "def words():\n",
    "    print(\"九月の终わりの晴れ间は夏がまだ残っていて\\n照りつける日差しと共に追忆を连れてくる\\n夕立が过ぎ去った空　「ソフトクリームのようだね」と\\n\")\n",
    "print('入道云指さした君に会いたいなぁ\\n揺れる揺れる　心と心がまた揺らいでいる\\n受け入れたつもりでいたのにいつの间にか　记忆も存在も手が届かないとこに隠すようにして/nはぐらかしてた/n')\n",
    "words()\n",
    "print('はぐらかしてた/n时が解决してくれるとよく耳にするけれど/nでも　解决が“忘れること”なら仆はそれを望んじゃいない/n思い出は时に暧昧で　美しくすり替わっていく/nそれでもいい　そうだとしても忘れたくない')\n",
    "words()\n",
    "words()\n",
    "print('君に会いたいなぁ/n风に乗って　香る金木犀が仆に伝えている/nもう夏は终わってるんだよ、と/nいつの日にかこの季节を越えて歩き出せたなら　また记忆の中で/n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "均值=8.000000 \n",
      "方差=22.000000 \n",
      "n=10\n",
      "\n",
      "均值=32.500000 \n",
      "方差=1236.272727 \n",
      "n=12\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def numbers(*arg):\n",
    "        sum=0\n",
    "        n=len(arg)\n",
    "        for i in arg:\n",
    "            sum+= float(i)\n",
    "        mean=sum/n\n",
    "        ss=0\n",
    "        for i in arg:\n",
    "            ss=ss+(i-mean)**2\n",
    "            variance=ss/(n-1)\n",
    "        print('均值=%f' % mean,\n",
    "               '\\n方差=%f'  % variance,\n",
    "                '\\nn=%d\\n' %n)\n",
    "numbers(7,9,10,1,3,4,7,10,12,17)\n",
    "numbers(19,90,12,6,19,84,7,10,19,96,7,21)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "选择输出标准差还是方差，1代表方差哦🌝\n",
      "1\n",
      "n=10 \n",
      "均值=8.000000\n",
      "方差=22.000000\n",
      "\n",
      "选择输出标准差还是方差，1代表方差哦🌝\n",
      "2\n",
      "n=12 \n",
      "均值=32.500000\n",
      "标准差=35.160670\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def numbers(*arg):\n",
    "        sum=0\n",
    "        n=len(arg)\n",
    "        for i in arg:\n",
    "            sum+= float(i)\n",
    "        mean=sum/n\n",
    "        ss=0\n",
    "        for i in arg:\n",
    "            ss=ss+(i-mean)**2\n",
    "            variance=ss/(n-1)\n",
    "        print('选择输出标准差还是方差，1代表方差哦🌝')\n",
    "        choice=int(input())\n",
    "        print('n=%d' %n,\n",
    "               '\\n均值=%f' % mean )\n",
    "        if choice==1:\n",
    "                print('方差=%f\\n'  % variance)\n",
    "        else:\n",
    "             print('标准差=%f\\n'  % variance**0.5) \n",
    "numbers(7,9,10,1,3,4,7,10,12,17)\n",
    "numbers(19,90,12,6,19,84,7,10,19,96,7,21)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "选择输出标准差还是方差，1代表方差哦🌝\n",
      "1\n",
      "选择输出均值的标准误、最大值、最小值或是不输出，1代表输出标准误、最大值及最小值👀\n",
      "1\n",
      "n=10 \n",
      "均值=8.000000\n",
      "方差=22.000000\n",
      "\n",
      "标准误=1.483240 最大值=17.000000 \n",
      "最小值=1.000000\n",
      "\n",
      "选择输出标准差还是方差，1代表方差哦🌝\n",
      "0\n",
      "选择输出均值的标准误、最大值、最小值或是不输出，1代表输出标准误、最大值及最小值👀\n",
      "1\n",
      "n=12 \n",
      "均值=32.500000\n",
      "标准差=35.160670\n",
      "\n",
      "标准误=10.150011 最大值=96.000000 \n",
      "最小值=6.000000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def numbers(*arg):\n",
    "        sum=0\n",
    "        n=len(arg)\n",
    "        for i in arg:\n",
    "            sum+= float(i)\n",
    "        mean=sum/n\n",
    "        ss=0\n",
    "        for i in arg:\n",
    "            ss=ss+(i-mean)**2\n",
    "            variance=ss/(n-1)\n",
    "            standard_error=variance**0.5/n**0.5\n",
    "        print('选择输出标准差还是方差，1代表方差哦🌝')\n",
    "        choice1=int(input())\n",
    "        print('选择输出均值的标准误、最大值、最小值或是不输出，1代表输出标准误、最大值及最小值👀')\n",
    "        choice2=int(input())\n",
    "        print('n=%d' %n,\n",
    "               '\\n均值=%f' % mean )\n",
    "        if choice1==1:\n",
    "                print('方差=%f\\n'  % variance)\n",
    "        else:\n",
    "                print('标准差=%f\\n'  % variance**0.5) \n",
    "        if choice2==1:\n",
    "             print('标准误=%f'  % standard_error,\n",
    "                     '最大值=%f' % max(arg),     \n",
    "                     '\\n最小值=%f\\n' % min(arg)) \n",
    "numbers(7,9,10,1,3,4,7,10,12,17)\n",
    "numbers(19,90,12,6,19,84,7,10,19,96,7,21)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
